load("@build_bazel_rules_android//android:rules.bzl", "android_binary")
load(
    "//tensorflow/lite:build_def.bzl",
    "tflite_copts",
    "tflite_jni_binary",
)

package(
    default_visibility = ["//visibility:public"],
    licenses = ["notice"],  # Apache 2.0
)

filegroup(
    name = "assets",
    srcs = [
        "@tflite_smartreply//:model_files",
    ],
)

android_binary(
    name = "SmartReplyDemo",
    srcs = glob(["java/**/*.java"]),
    aapt_version = "aapt2",
    assets = [":assets"],
    assets_dir = "",
    custom_package = "com.example.android.smartreply",
    manifest = "AndroidManifest.xml",
    nocompress_extensions = [
        ".tflite",
    ],
    resource_files = glob(["res/**"]),
    tags = ["manual"],
    deps = [
        ":smartreply_runtime",
        "@androidsdk//com.android.support:support-v13-25.2.0",
        "@androidsdk//com.android.support:support-v4-25.2.0",
    ],
)

cc_library(
    name = "smartreply_runtime",
    srcs = ["libsmartreply_jni.so"],
    visibility = ["//visibility:public"],
)

tflite_jni_binary(
    name = "libsmartreply_jni.so",
    deps = [
        ":smartreply_jni_lib",
    ],
)

cc_library(
    name = "smartreply_jni_lib",
    srcs = [
        "smartreply_jni.cc",
    ],
    copts = tflite_copts(),
    linkopts = [
        "-lm",
        "-ldl",
    ],
    deps = [
        "//tensorflow/lite:framework",
        "//tensorflow/lite/java/jni",
        "//tensorflow/lite/models/smartreply:predictor_lib",
    ],
    alwayslink = 1,
)
